package itheima.com.Day08Word;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapWord {
    public static void main(String[] args) {
    /* (1) 定义一个学生类Student，包含属性：姓名(String name)、年龄( int age)
    (2) 定义Map集合，用Student对象作为key，用字符串(此表示表示学生的住址) 作为value
     (3) 利用四种方式遍历Map集合中的内容，格式：key::value*/
        Map<Student,String> map = new HashMap<>();

        Student s1 = new Student("小弟弟",23);
        Student s2 = new Student("小憨憨",25);
        Student s3 = new Student("小皮皮",22);
        map.put(s1,"中原");
        map.put(s2,"羌");
        map.put(s3,"麓谷");

        Set<Student> students = map.keySet();
        for (Student key : students) {
            String value = map.get(key);
            System.out.println(key+"---"+value);
        }
        System.out.println("-------------");

        Set<Map.Entry<Student, String>> entries = map.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"---"+value);
        }
        System.out.println("---------------");
        map.forEach((Student key,String value)->{
            System.out.println(key+"---"+value);
        });
        System.out.println("---------------");
    }
}
